package com.gzdh.tang.comm.util;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ObjectUtil {

    public static String getStr(Object object){
        return object != null ? object.toString().trim() : "";
    }

    public static Integer getInt(Object object){
        return object != null ? Integer.parseInt(object.toString().trim()) : 0;
    }

    public static Double getDouble(Object object){
        return object != null ? Double.parseDouble(object.toString().trim()) : 0;
    }

    public static BigInteger getBigInt(Object object){
        return object != null ? new BigInteger(object.toString().trim()) : new BigInteger("0");
    }

    public static Long getLong(Object object){
        return object != null ? Long.parseLong(object.toString().trim()) : 0;
    }

    public static BigDecimal getBigDecimal(Object object){
        return object != null ? new BigDecimal(object.toString().trim()) : new BigDecimal(0);
    }

    public static Boolean getBoolean(Object object){
        return object != null && Boolean.parseBoolean(object.toString().trim());
    }

    public static String getFormatDateByTimestamp(Object object){
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        date.setTime(getLong(object));
        return dateFormat.format(date);
    }
}
